

*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
*   Subject:							Political Science
*	Module:         					Empirical methods 2
*   Lecture:  							Praxiskurs quantitative Datenanalyse und Replikation
*	Date:								22.05.2023

*   Name:								Niklas Maximilian Reinecke
*	Matrikelnummer/Registration number: 4172903
*	Hausarbeit/Essay:					Replication of Levin et al. (2021)
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*

*********************************************************************************************Setup commands*********************************************************************************************
clear all
version 17.0
set more off 
*cd "C:\Users\nikma\OneDrive\Shared Dokumente\Dokumente\Replicationsmaterialien" //Working directory LapTop
*cd "D:\OneDrive\Shared Dokumente\Dokumente\Replicationsmaterialien" //Working directory PC

cd "C:\Users\ba72loko\projects\replication paper ZfVP\calculations"

capture log close //optional
log using "Study_2_log_file.log", replace //output log


*** Loading dataset
use "data\Study_2\original_data.dta", clear //opening replication dataset
describe

*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Generating variables
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
**generating New robust democracy dummy variable**
gen new_robust_democracy6 = . //generating a new variable for the fixed version of robust_democracy6
replace new_robust_democracy6 = robust_democracy6
replace new_robust_democracy6 = 0 if polity2 == . //missings von polity2 als new_robust_autocracy6 == 0 codiert 


*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Labeling of varlabels
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
label variable marshallsum "All coup attempts"
label variable milcoupsum "Military coup attempts"
label variable milcoupsuccess_mm "Successful military coups"
label variable troops "Peacekeepers"
label variable robust_autocracy6 "Robust autocracy"
label variable robust_anocracy5 "Anocracy"
label variable robust_democracy6 "Robust democracy"
label variable population2000 "Population"
label variable gdpcap "GDP per capita"
label variable durable "Regime durability"
label variable conflict "Political violence"
label variable milexp "Military expenditure"
label variable exsol "Expenditure per soldier"
label variable effective_number "Effective organizations"
label variable elf "Ethnic fractionalization"
label variable aut_troops "Autocracy Peacekeepers"
label variable ano_troops "Anocracy Peacekeepers"
label variable dem_troops "Democracy Peacekeepers"
label variable aut_troops_round "Autocracy Peacekeepers rounded"
label variable ano_troops_round "Anocracy Peacekeepers rounded"
label variable dem_troops_round "Democracy Peacekeepers rounded"
label variable new_robust_democracy6 "New robust democracy"


*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Main Model
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
*************************************************************************************************Table B1 Supplementary Appendix ***********************************************************************
*Table 1: Poisson regression, new robus democracy variable as IV, with year fixed effects

est clear

eststo: poisson milcoupsum robust_autocracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)

estat gof //testing the fit of the poisson model

eststo: poisson milcoupsum robust_anocracy5##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)

estat gof //testing the fit of the poisson model

eststo: poisson milcoupsum robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)

estat gof //testing the fit of the poisson model

eststo: poisson milcoupsum new_robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)

estat gof //testing the fit of the poisson model

esttab using "tables\Study_2\Table_B1.rtf", b(3) se(3) star(+ 0.1 * 0.05 ** 0.01 *** 0.001) ///
title(Table B1. Determinants of military coup attempts, 1991–2013; Poisson regression with year fixed effects, with new democracy dummy variable) ///
drop(*.year 0.robust_autocracy6 0.robust_autocracy6#c.troops 0.robust_anocracy5 0.robust_anocracy5#c.troops ///
0.robust_democracy6 0.robust_democracy6#c.troops 0.new_robust_democracy6 0.new_robust_democracy6#c.troops) ///
label varlabels(1.robust_autocracy6 "Robust autocracy" 1.robust_autocracy6#c.troops "Robust autocracy * Peacekeepers" ///
1.robust_anocracy5 "Anocracy" 1.robust_anocracy5#c.troops "Anocracy * Peacekeepers" 1.robust_democracy6 "Robust democracy" ///
1.robust_democracy6#c.troops "Robust democracy * Peacekeepers" 1.new_robust_democracy6 "New robust democracy" ///
1.new_robust_democracy6#c.troops "New robust democracy * Peacekeepers" _cons "Constant") ///
order(1.robust_autocracy6 1.robust_autocracy6#c.troops 1.robust_anocracy5 1.robust_anocracy5#c.troops 1.robust_democracy6 ///
1.robust_democracy6#c.troops 1.new_robust_democracy6 1.new_robust_democracy6#c.troops troops gdpcap durable conflict milexp exsol population2000) ///
nonumbers modelwidth(6) eqlabel(none) varwidth(33) replace

est clear

*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Figures
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*

************************************************************************************************FIGURE B1 and B2 Supplementary Appendix ****************************************************************
est clear

gen troops_round = .
replace troops_round = troops if troops != .
replace troops_round = round(troops_round, 1)


*model 1a: autocracy rounded
poisson milcoupsum robust_autocracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_autocracy6) post
est store m1a

*model 1b: autocracy rounded year fixed effects
poisson milcoupsum robust_autocracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_autocracy6) post
est store m1b

*model 2a: autocracy
poisson milcoupsum robust_autocracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_autocracy6) post
est store m2a

*model 2b: autocracy year fixed effects
poisson milcoupsum robust_autocracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_autocracy6) post
est store m2b

*model 3a: anocracy rounded
poisson milcoupsum robust_anocracy5##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_anocracy5) post
est store m3a

*model 3b: anocracy rounded year fixed effects
poisson milcoupsum robust_anocracy5##c.troops_round population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_anocracy5) post
est store m3b

*model 4a: anocracy
poisson milcoupsum robust_anocracy5##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_anocracy5) post
est store m4a

*model 4b: anocracy year fixed effects
poisson milcoupsum robust_anocracy5##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_anocracy5) post
est store m4b

*model 5a: democracy rounded
eststo: poisson milcoupsum robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_democracy6) post
est store m5a

*model 5b: democracy rounded year fixed effects
eststo: poisson milcoupsum robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_democracy6) post
est store m5b

*model 6a: democracy
eststo: poisson milcoupsum robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_democracy6) post
est store m6a

*model 6b: democracy year fixed effects
eststo: poisson milcoupsum robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(robust_democracy6) post
est store m6b

*model 7a: New democracy rounded
eststo: poisson milcoupsum new_robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(new_robust_democracy6) post
est store m7a

*model 7b: New democracy rounded year fixed effects
eststo: poisson milcoupsum new_robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(new_robust_democracy6) post
est store m7b

*model 8a: New democracy
eststo: poisson milcoupsum new_robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(new_robust_democracy6) post
est store m8a

*model 8b: New democracy year fixed effects
eststo: poisson milcoupsum new_robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol i.year, cluster(ccode)
margins, dydx(new_robust_democracy6) post
est store m8b

*coefplot
coefplot (m1a, label(Autocracy * Rounded Peacekeepers) offset(0.1)) ///
(m2a, label(Autocracy) offset(-0.1)) ///
(m3a, label(Anocracy * Rounded Peacekeepers) offset(0.1)) ///
(m4a, label(Anocracy) offset(-0.1)) ///
(m5a, label(Democracy * Rounded Peacekeepers) offset(0.1)) ///
(m6a, label(Democracy) offset(-0.1)) ///
(m7a, label(New Democracy * Rounded Peacekeepers) offset(0.1)) ///
(m8a, label(New Democracy) offset(-0.1)), xline(0) ///
title("", size(medsmall) span) xtitle("Average marginal effects", size(small)) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall)) legend(size(vsmall) span)

graph export "figures\Study_2\Figure_B1_without_year_fe.png", replace


*coefplot
coefplot (m1b, label(Autocracy * Rounded Peacekeepers) offset(0.1))  ///
(m2b, label(Autocracy) offset(-0.1)) ///
(m3b, label(Anocracy * Rounded Peacekeepers) offset(0.1)) ///
(m4b, label(Anocracy) offset(-0.1)) ///
(m5b, label(Democracy * Rounded Peacekeepers) offset(0.1)) ///
(m6b, label(Democracy) offset(-0.1)) ///
(m7b, label(New Democracy * Rounded Peacekeepers) offset(0.1)) ///
(m8b, label(New Democracy) offset(-0.1)), xline(0) ///
title("", size(medsmall) span) xtitle("Average marginal effects", size(small)) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall)) legend(size(vsmall) span)

graph export "figures\Study_2\Figure_B2_with_year_fe.png", replace

************************************************************************************************FIGURE B2***********************************************************************************************

****Marginal Effects Plots by Troop Size****

*model 1a: autocracy rounded
poisson milcoupsum robust_autocracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_autocracy6) at (troops_round = (0(1)10)) post
marginsplot, ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops (rounded)", size(medsmall))  ///
	title("Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops_round, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.1.gph", replace

		
*model 2a: autocracy
poisson milcoupsum robust_autocracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_autocracy6) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.2.gph", replace


*model 3a: anocracy rounded
poisson milcoupsum robust_anocracy5##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_anocracy5) at (troops_round = (0(1)10)) post
marginsplot, ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops (rounded)", size(medsmall))  ///
	title("Anocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops_round, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.3.gph", replace


*model 4a: anocracy
poisson milcoupsum robust_anocracy5##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_anocracy5) at (troops =  (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("Anocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.4.gph", replace


*model 5a: democracy rounded
eststo: poisson milcoupsum robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_democracy6) at (troops_round = (0(1)10)) post
marginsplot, ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops (rounded)", size(medsmall))  ///
	title("Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops_round, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.5.gph", replace


*model 6a: democracy
eststo: poisson milcoupsum robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(robust_democracy6) at (troops =  (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.6.gph", replace


*model 7a: New democracy rounded
eststo: poisson milcoupsum new_robust_democracy6##c.troops_round population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(new_robust_democracy6) at (troops_round = (0(1)10)) post
marginsplot, ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops (rounded)", size(medsmall))  ///
	title("New Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops_round, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.7.gph", replace

*model 8a: New democracy
eststo: poisson milcoupsum new_robust_democracy6##c.troops population2000 gdpcap durable conflict milexp exsol, cluster(ccode)
margins, dydx(new_robust_democracy6) at (troops =  (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("New democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B2.8.gph", replace


graph combine "figures\Study_2\B2.1.gph" "figures\Study_2\B2.3.gph" "figures\Study_2\B2.5.gph" "figures\Study_2\B2.7.gph", col(2) 
graph export "figures\Study_2\Figure_B3_AME_by_troop_rounded.png", as(png) name("Graph") replace
 
graph combine "figures\Study_2\B2.2.gph" "figures\Study_2\B2.4.gph" "figures\Study_2\B2.6.gph" "figures\Study_2\B2.8.gph", col(2) 
graph export "figures\Study_2\Figure_B4_AME_by_troop.png", as(png) name("Graph") replace
 

*** 
save "data\Study_2\Technical_Replication.dta", replace 

*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* V-Dem Regime Types 
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
************************************************************************************************FIGURE B3***********************************************************************************************

use "data\Study_2\V-Dem-CY-Full+Others-v12.dta", clear //opening V-Dem dataset
describe

rename COWcode ccode //renameing COWcode to ccode

gsort ccode year

*deleting all observations from before 1991 and after 2013
drop if year < 1991
drop if year > 2013

*Matching differences between CoW and Polity4 ccodes
replace ccode = 529 if ccode == 530
replace ccode = 341 if ccode == 347
replace ccode = 348 if ccode == 341
replace ccode = 769 if ccode == 770
replace ccode = 324 if ccode == 325
replace ccode = 342 if ccode == 345
replace ccode = 347 if ccode == 345
replace ccode = 525 if ccode == 626
replace ccode = 626 if ccode == 625
replace ccode = 364 if ccode == 365
replace ccode = 818 if ccode == 816
replace ccode = 347 if ccode == 345

gsort ccode year

***Merging Data***
merge m:m year ccode using "data\Study_2\Technical_Replication.dta"
drop _merge



*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Generating variables
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
*Creating Regime dummy variables based on the regime type data of the Regimes of the World measure with categories for ambiguous cases
gen RoW_Demo = 0
replace RoW_Demo = 1 if v2x_regime_amb >= 6
replace RoW_Demo = . if v2x_regime_amb ==.

gen RoW_Ano = 0
replace RoW_Ano = 1 if v2x_regime_amb == 3 | v2x_regime_amb == 4 | v2x_regime_amb == 5
replace RoW_Ano = . if v2x_regime_amb ==.

gen RoW_Auto = 0
replace RoW_Auto = 1 if v2x_regime_amb <= 2
replace RoW_Auto = . if v2x_regime_amb ==.


*Creating Regime dummy variables based on the regime type data and categories of the Regimes of the World measure
gen Lib_Demo = 0
replace Lib_Demo = 1 if v2x_regime == 3
replace Lib_Demo = . if v2x_regime ==.

gen Ele_Demo = 0
replace Ele_Demo = 1 if v2x_regime == 2
replace Ele_Demo = . if v2x_regime ==.


gen Ele_Auto = 0
replace Ele_Auto = 1 if v2x_regime == 1
replace Ele_Auto = . if v2x_regime ==.

gen Clo_Auto = 0
replace Clo_Auto = 1 if v2x_regime == 0
replace Clo_Auto = . if v2x_regime ==.


*Creating troop dummy variables for each Polity4 regime type based on the regime type data of the Regimes of the World measure with categories for ambiguous cases
gen v_demo_troops = .
replace v_demo_troops = 0 if troops != .
replace v_demo_troops = troops if RoW_Demo == 1

gen v_ano_troops = .
replace v_ano_troops = 0 if troops != .
replace v_ano_troops = troops if RoW_Ano == 1

gen v_auto_troops = .
replace v_auto_troops = 0 if troops != .
replace v_auto_troops = troops if RoW_Auto == 1


*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Labeling of varlabels
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
label variable marshallsum "All coup attempts"
label variable milcoupsum "\fs24 Military coup attempts"
label variable milcoupsuccess_mm "Successful military coups"
label variable troops "Peacekeepers"
label variable robust_autocracy6 "Polity Robust autocracy"
label variable robust_anocracy5 "Polity Anocracy"
label variable robust_democracy6 "Polity Robust democracy"
label variable new_robust_democracy6 "New Polity robust democracy"
label variable RoW_Demo "RoW Democracy"
label variable RoW_Ano "RoW Anocracy"
label variable RoW_Auto "RoW Autocracy"
label variable Lib_Demo "Liberal democracy"
label variable Ele_Demo "Electoral democracy"
label variable Ele_Auto "Electoral autocracy"
label variable Clo_Auto "Closed autocracy"
label variable population2000 "Population"
label variable gdpcap "GDP per capita"
label variable durable "Regime durability"
label variable conflict "Political violence"
label variable milexp "Military expenditure"
label variable exsol "Expenditure per soldier"
label variable effective_number "Effective organizations"
label variable elf "Ethnic fractionalization"
	   
gsort ccode year


*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
* Figures
*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*
************************************************************************************************FIGURE B5, B6 and B7 ***********************************************************************************
**Figure B3. Marginal effect of interaction between regime type and peacekeepers**

est clear

**model 4a: RoW autocracy
poisson milcoupsum RoW_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Auto) post
est store m4a

**model 4b: RoW autocracy with year fixed effects
poisson milcoupsum RoW_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Auto) post
est store m4b

**model 5a: RoW anocracy
poisson milcoupsum RoW_Ano##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Ano) post
est store m5a

**model 5b: RoW anocracy with year fixed effects
poisson milcoupsum RoW_Ano##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Ano) post
est store m5b

**model 6a: RoW democracy
poisson milcoupsum RoW_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Demo) post
est store m6a

**model 6b: RoW democracy with year fixed effects
poisson milcoupsum RoW_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Demo) post
est store m6b

*coefplot
coefplot ///
(m4a, label(RoW Autocracy) offset(0.2)) (m4b, label(RoW Autocracy year fixed effects) offset(-0.2)) ///
(m5a, label(RoW Anocracy) offset(0.2)) (m5b, label(RoW Anocracy year fixed effects) offset(-0.2)) ///
(m6a, label(RoW Democracy) offset(0.2)) (m6b, label(RoW Democracy year fixed effects) offset(-0.2)), xline(0) ///
title("", size(medsmall) span) xtitle("Average marginal effects", size(small)) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall)) legend(size(vsmall) span)
 
graph export "figures\Study_2\Figure_B5.png", replace


**model 4a: RoW autocracy
poisson milcoupsum RoW_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Auto) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.1.gph", replace
 
**model 4b: RoW autocracy with year fixed effects
poisson milcoupsum RoW_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Auto) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.2.gph", replace

**model 5a: RoW anocracy
poisson milcoupsum RoW_Ano##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Ano) at (troops = (0(0.05)9.8))post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Anocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.3.gph", replace

**model 5b: RoW anocracy with year fixed effects
poisson milcoupsum RoW_Ano##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Ano) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Anocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.4.gph", replace


**model 6a: RoW democracy
poisson milcoupsum RoW_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup, cluster(ccode)
margins, dydx(RoW_Demo) at (troops = (0(0.05)9.8))  post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.5.gph", replace


**model 6b: RoW democracy with year fixed effects
poisson milcoupsum RoW_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(RoW_Demo) at (troops = (0(0.05)9.8))  post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B3.6.gph", replace


graph combine "figures\Study_2\B3.1.gph" "figures\Study_2\B3.3.gph" "figures\Study_2\B3.5.gph", col(2) 
graph export "figures\Study_2\Figure_B6_AME_by_reg_type.png", as(png) name("Graph") replace
 
graph combine "figures\Study_2\B3.2.gph" "figures\Study_2\B3.4.gph" "figures\Study_2\B3.6.gph", col(2) 
graph export "figures\Study_2\Figure_B7_AME_by_reg_type_year_FE.png", as(png) name("Graph") replace

************************************************************************************************FIGURE 3************************************************************************************************
**Figure B8 and B9. Marginal effect of interaction between RoW regime type and peacekeepers**

est clear

**model 1: Closed autocracy with year fixed effects
poisson milcoupsum Clo_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Clo_Auto) post
est store m1

**model 2: Electoral autocracy with year fixed effects
poisson milcoupsum Ele_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Ele_Auto) post
est store m2

**model 3: Electoral democracy with year fixed effects
poisson milcoupsum Ele_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Ele_Demo) post
est store m3

*model 4: Liberal democracy with year fixed effects
eststo: poisson milcoupsum Lib_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Lib_Demo) post
est store m4

*coefplot
coefplot (m1, label(Closed Autocracy) offset(0)) (m2, label(Electoral Autocracy) offset(0)) ///
(m3, label(Electoral Democracy) offset(0)) (m4, label(Liberal Democracy) offset(0)), xline(0) ///
title("", size(medsmall) span) ///
subtitle("", size(small) span) xtitle("Average marginal effects", size(small)) ylabel(,labsize(small)) xlabel(,labsize(small)) legend(size(small) span)
 
graph export "figures\Study_2\Figure_B8.png", replace

*****AME by Troop size******


**model 1: Closed autocracy with year fixed effects
poisson milcoupsum Clo_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Clo_Auto) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Closed Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B9.1.gph", replace

**model 2: Electoral autocracy with year fixed effects
poisson milcoupsum Ele_Auto##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Ele_Auto) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Electoral Autocracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B9.2.gph", replace


**model 3: Electoral democracy with year fixed effects
poisson milcoupsum Ele_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Ele_Demo) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Electoral Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B9.3.gph", replace


*model 4: Liberal democracy with year fixed effects
eststo: poisson milcoupsum Lib_Demo##c.troops population2000 gdpcap durable conflict milexp exsol v2regsupgroupssize i.v2regimpgroup i.year, cluster(ccode)
margins, dydx(Lib_Demo) at (troops = (0(0.05)9.8)) post
marginsplot, ///
	recast(line) plot1opts(lcolor(gs8)) ciopt(color(black%20)) recastci(rarea) ///
	ytitle("AME", size(medsmall)) ///
	xtitle("Troops", size(medsmall))  ///
	title("RoW Liberal Democracy", size(medium)) yline(0, lcolor(red)) ///
	addplot(hist troops, /// adding histogram marginsplot graph
blcolor(black%30) fcolor(white%10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 "60%" 80 "80%" 100 "100%", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)))  legend(off)
graph save "figures\Study_2\B9.4.gph", replace


graph combine "figures\Study_2\B9.1.gph" "figures\Study_2\B9.2.gph" "figures\Study_2\B9.3.gph" "figures\Study_2\B9.4.gph", col(2) 
graph export "figures\Study_2\Figure_B9_AME_by_reg_type.png", as(png) name("Graph") replace
 

